package com.fenghongzhang.new1803a;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;

//自定义对话框
public class MyDialog extends Dialog {
    private TextView title;
    private TextView message;
    private Button no;
    private Button yes;

    //缓存一下.
    private String messageString;
    private String titleString;

    private String okString;

    //2,声明一下,当前的接口
    private YesOnClickListener yesonClickListener;

    //3,set方法
    public void setYesonClickListener(YesOnClickListener yesonClickListener) {
        this.yesonClickListener = yesonClickListener;
    }

    //1,自定义一个点击的接口
    public interface YesOnClickListener{
        void OnClick();
    }

    public MyDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.my_dialog_layout);

        title = (TextView) findViewById(R.id.title);
        message = (TextView) findViewById(R.id.message);
        no = (Button) findViewById(R.id.no);
        yes = (Button) findViewById(R.id.yes);


        if(messageString != null){
            message.setText(messageString);
        }

        if(titleString != null){
            title.setText(titleString);
        }

        if (okString != null){
            yes.setText(okString);
        }


        //4
        yes.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(yesonClickListener != null){
                    yesonClickListener.OnClick();
                }
                dismiss();
            }
        });




    }






    public void setTitleString(String titleString) {
        this.titleString = titleString;
    }

    public void setOkString(String okString) {
        this.okString = okString;
    }

    public void setMessageString(String messageString) {
        this.messageString = messageString;
    }
}
